let page = 1;
let limit = 8;
let cuisineId = 0;
layui.use(['laypage', 'layer'], function () {
    var laypage = layui.laypage
        , layer = layui.layer;
    //完整功能
    // let res=myAjax("/back/user/count",{},'get');
    laypage.render({
        elem: 'page'
        , count: myAjax("/front/product/findAll", data, 'get').count
        , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
        , jump: function (obj) {
            console.log(obj)
            // let page = {page: obj.curr, limit: obj.limit};
            //涉及到对象相加data+page;
            page = obj.curr;
            limit = obj.limit;
            cuisineId = sessionStorage.getItem("cuisineId");
            findProductAll(cuisineId);
        }
    });
});


// $(function () {
//     // let data = {page: 1, limit: 8, cuisineId: 0};
//     findProductAll(0);
// });

function findProductAll(cuisineId) {
    sessionStorage.setItem("cuisineId", cuisineId);
    let data = {page: page, limit: limit, cuisineId: cuisineId};

    $.ajax({
        url: '/front/product/findAll',
        data: data,
        type: 'get',
        dataType: 'json',
        success: function (res) {
            console.log(res);
            setProductModelList(res.productModelList);

        }
    })
}

function setProductModelList(data) {
    let html = '';
    data.forEach(function (elem) {
        html += '<div>\n' +
            '                            <div><img src="' + elem.imgHref + '" height="300" width="300"/></div>\n' +
            '                            <div>' + elem.name + '</div>\n' +
            '                            <div>\n' +
            '                                价格\n' +
            '                                <price>' + elem.normalPrice + '</price>\n' +
            '                            </div>\n' +
            '                            <div>\n' +
            '                                ' + elem.content + '\n' +
            '                            </div>\n' +
            '                        </div>';
    });
    $("#productList").html(html);
}